package cn.tedu.boot32.controller;

import cn.tedu.boot32.entity.User;
import cn.tedu.boot32.mapper.UserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class UserController {
    @Autowired
    UserMapper mapper;

    @RequestMapping("/reg")
    public String reg(User user){
        //通过用户输入的用户名查询是否存在数据 u代表查询回来的用户信息
        User u= mapper.selectByUsername(user.getUsername());
        if(u!=null){
            return "用户名已存在";
        }
        mapper.insert(user);
        return "注册成功<a href='/login.html'>点击登录</a>";
    }
    @RequestMapping("/login")
    public String login(User user){

       User u=mapper.selectByUsername(user.getUsername());
       if(u==null){
           return "用户名不存在";
       }else{
           if(u.getPassword().equals(user.getPassword())){
               return "登陆成功";
           }
           return "密码错误!";
       }

    }
}
